//
//  WhiteboardViewController.swift
//  TTProduct-macOS
//
//  Created by Toj on 3/5/21.
//

import Cocoa

import TTBLL_macOS

class WhiteboardViewController: TTViewController {
    private lazy var nameTextField: NSTextField = {
       let view = NSTextField()
        return view
    }()
    
    private lazy var annotationView: NSView = {
       let view = NSView()
        view.tt_backgroundColor = .gray
        return view
    }()
    
    private lazy var startButton: TTButton = {
       let view = TTButton()
        view.tt_backgroundColor = .red
        view.tt_setTitle("开始", for: .normal)
        view.tt_setTitleColor(.white, for: .normal)
        view.tt_addTarget(self, action: #selector(self.didTapStart), for: .leftMouseUp)
        return view
    }()
    
    private lazy var stopButton: TTButton = {
       let view = TTButton()
        view.tt_backgroundColor = .red
        view.tt_setTitle("结束", for: .normal)
        view.tt_setTitleColor(.white, for: .normal)
        view.tt_addTarget(self, action: #selector(self.didTapStop), for: .leftMouseUp)
        return view
    }()
    
    private var annotationBLL: TTAnnotationManager?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupMakeAddSubviews()
        
        setupMakeLayoutSubviews()
        
        setupMakeInit()
    }
}

extension WhiteboardViewController {
    @objc private func didTapStart() {
        print(#function)
        annotationBLL?.joinChannel(view: annotationView)
//        annotationBLL?.setRoleType(role: .attendee)
        
    }
    
    @objc private func didTapStop() {
        print(#function)
        annotationBLL?.stopAnnotation()
    }
}

extension WhiteboardViewController {
    
    private func setupMakeInit() {
        let annotation = TTAnnotationManager.shared
        annotationBLL = annotation
        let a = TTAnnotationModel()
        annotation.setupParameters(annotation: a)
    }
    
    private func setupMakeAddSubviews() {
        view.addSubview(annotationView)
        view.addSubview(startButton)
        view.addSubview(stopButton)
        view.addSubview(nameTextField)
    }
    
    private func setupMakeLayoutSubviews() {
        
        annotationView.frame = CGRect(x: 0, y: 0, width: 800, height: 600)
        startButton.frame = CGRect(x: 20, y: 650, width: 50, height: 30)
        stopButton.frame = CGRect(x: 100, y: 650, width: 50, height: 30)
        nameTextField.frame = CGRect(x: 100, y: 750, width: 50, height: 30)
    }
}
